﻿Imports System.Data.OleDb
Public Class Sinónimos

    Private Sub btn_SINONIMOS_Volver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINONIMOS_Volver.Click
        Me.Close()
    End Sub

    Private Sub btn_SINONIMOS_Añadir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINONIMOS_Añadir.Click
        Dim nuevo_sinonimo As String
        nuevo_sinonimo = InputBox("Teclea el nombre para el nuevo sinónimo:", "Añadir Sinónimo")
        If nuevo_sinonimo = "" Then
            MsgBox("No has introducido el nombre de ningún sinónimo. Inténtalo de nuevo", , "SINÓNIMO EN BLANCO")
            Exit Sub
        End If
        lsb_SINONIMOS_Objetos.Items.Add(nuevo_sinonimo)

        '==============================================================================================
        'COMENTARIOS. AÑADIR UN SINOMIMO DEL OBJETO EN LA B.D.
        '==============================================================================================

        'Se establece la conexión con la base de datos.
        Dim sCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & txtBase
        Dim ODbConn As New OleDb.OleDbConnection(sCnn)
        ODbConn.Open()

        'Se crea un objeto Command 
        'Se ejecuta una consulta de actualización que graba el Nombre del Juego
        Dim LACommand As New OleDb.OleDbCommand("INSERT INTO SINONIMOS_OBJETOS (objeto, sinonimo) values (" & "'" & txt_SINONIMOS_Objeto.Text & "'" & "," & "'" & nuevo_sinonimo & "'" & ")", ODbConn) ' & "'" & "WHERE OBJETOS.nombre=" & "'" & txt_Nombre_Objeto.Text &
        Dim LADataReader As OleDbDataReader = LACommand.ExecuteReader(CommandBehavior.CloseConnection)

        'Libera memoria
        LACommand.Dispose()
        ODbConn.Close()


    End Sub

    Private Sub btn_SINONIMOS_Eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINONIMOS_Eliminar.Click
        '==============================================================================================
        'COMENTARIOS. ELIMINAR UN SINOMIMO DEL OBJETO EN LA B.D.
        '==============================================================================================

        Dim sCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & txtBase
        Dim ODbConn As New OleDb.OleDbConnection(sCnn)
        ODbConn.Open()

        Dim SinonimosCommand As New OleDb.OleDbCommand("DELETE FROM SINONIMOS_OBJETOS WHERE SINONIMOS_OBJETOS.sinonimo= " & "'" & lsb_SINONIMOS_Objetos.SelectedItem & "'" & " and " & "SINONIMOS_OBJETOS.objeto= " & "'" & txt_SINONIMOS_Objeto.Text & "'", ODbConn)
        Dim SinonimosDataReader As OleDb.OleDbDataReader = SinonimosCommand.ExecuteReader(CommandBehavior.CloseConnection)

        lsb_SINONIMOS_Objetos.Items.Remove(lsb_SINONIMOS_Objetos.SelectedItem)
        SinonimosCommand.Dispose()
        ODbConn.Close()
    End Sub

    Private Sub Sinónimos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Sinónimos_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        btn_SINONIMOS_Añadir.Focus()
    End Sub
End Class